/**  
 * @Title: PermissionController.java
 * @Package com.limit.control.admin
 * @author maoyun(maoyun0903@163.com)
 * @date 2014-4-3 下午08:58:38
 * @version V1.0
 */ 
package com.limit.control.admin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.aop.Before;
import com.jfinal.plugin.ehcache.CacheKit;
import com.limit.constant.Constant;
import com.limit.control.admin.validate.ModuleValidator;
import com.limit.model.Actor;
import com.limit.model.ActorModule;
import com.limit.model.Module;

/** 
 * <br/>
 * @author maoyun(maoyun0903@163.com)
 * @date 2014-4-3 下午08:58:38 
 * @version V1.0
 */

public class ModuleController extends BaseController {

	public void index(){
		this.setAttr("action", this);
		render("modules.html");
	}
	
	/**
	 * 根据pid获取列表
	 */
	public List<Module> getListByPid(int pid){
		
		return Module.dao.find("select * from module where pid=?", pid);
		
	}
	
	public void view(){
		this._commonSetId();
		Module module = new Module();
		if(id > 0){
			module = Module.dao.findById(id);
		}
		this.setAttr("module", module);
		this.setAttr("plist", Module.dao.find("select * from module where pid=?",0));
		render("module_view.html");
		
	}

	/**
	 * 添加
	 */
	@Before(ModuleValidator.class)
	public void save(){
		this.getModel(Module.class).save();
		this.index();
		
	}
	
	/**
	 * 修改
	 */
	@Before(ModuleValidator.class)
	public void update(){
		this.getModel(Module.class).update();
		this.index();
		
		
	}
	
	/**
	 * 删除操作
	 */
	public void delete(){
		this._commonSetId();
		this.getModel(Module.class).deleteById(id);
		this.index();
	}
	
	/**
	 * 刷新缓存
	 */
	public void refreshCache(){
		String username = this.getSessionAttr(Constant.UserName); 
		String actorId 	= this.getSessionAttr(Constant.ActorId);
		CacheKit.remove(Constant.CacheActorPermission, username);
		this._refreshPermissionCache(actorId, username);
		this.index();
	}
	
	
}
